#!/usr/bin/env python
PACKAGE = "depth_segmentation"

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

# General params.
general_params = gen.add_group("general_params")
general_params.add("dilate_depth_image", bool_t, 0,
                   "Dilate the registered depth image.", False)
general_params.add("dilation_size", int_t, 0,
                   "Size of the dilation for the registered depth image.", 1, 1,
                   15)

# Surface normal estimation parameters.
surface_normal = gen.add_group("surface_normal")
surface_normal.add(
    "normals_method", int_t, 0,
    "Normal estimation Method (0: Fals, 1: Linemod, 2: Sri, 3: "
    "DepthWindowFilter)", 3, 0, 3)
surface_normal.add(
    "normals_distance_factor_threshold", double_t, 0,
    "Maximal Euclidean distance factor (depending on the "
    "midpoint distance to the camera) for a point to be "
    "considered in the neighborhood.", 0.05, 0.0, 1.0)
surface_normal.add("normals_window_size", int_t, 0,
                   "The window size for the neighborhood.", 13, 3, 31)
surface_normal.add("normals_display", bool_t, 0,
                   "Display the estimated normals.", False)

# Depth discontinuity parameters.
depth_discontinuity = gen.add_group("depth_discontinuity")
depth_discontinuity.add("depth_discontinuity_use_depth_discontinuity", bool_t,
                        0, "Use depth discontinuity map.", True)
depth_discontinuity.add("depth_discontinuity_kernel_size", int_t, 0,
                        "The kernel size for the neighborhood.", 3, 1, 25)
depth_discontinuity.add(
    "depth_discontinuity_ratio", double_t, 0,
    "Ratio between maximum local Euclidean distance and original depth for "
    "a point to be considered as depth discontinuity.", 0.01, 0.0, 5.0)
depth_discontinuity.add("depth_discontinuity_display", bool_t, 0,
                        "Display the depth discontinuity map.", False)

# Maximum distance parameters.
max_distance = gen.add_group("max_distance")
max_distance.add("max_distance_use_max_distance", bool_t, 0,
                 "Use max distance map.", True)
max_distance.add("max_distance_window_size", int_t, 0,
                 "The window size for the neighborhood.", 1, 1, 9)
max_distance.add("max_distance_exclude_nan_as_max_distance", bool_t, 0,
                 "Exclude nans as max distances.", False)
max_distance.add(
    "max_distance_ignore_nan_coordinates", bool_t, 0,
    "Exclude all values that have at least one nan in them for "
    "the max distance calculation.", False)
max_distance.add("max_distance_use_threshold", bool_t, 0,
                 "Enable a threshold value for the max distance calculation.",
                 True)
max_distance.add(
    "max_distance_noise_thresholding_factor", double_t, 0,
    "Noise thresholding factor, depending on the midpoint "
    "distance.", 10.0, 0.0, 30.0)
max_distance.add("max_distance_sensor_noise_param_1st_order", double_t, 0,
                 "Noise model first order parameter.", 0.0012, 0.0, 1.0)
max_distance.add("max_distance_sensor_noise_param_2nd_order", double_t, 0,
                 "Noise model second order parameter.", 0.0019, 0.0, 1.0)
max_distance.add("max_distance_sensor_noise_param_3rd_order", double_t, 0,
                 "Noise model third order parameter.", 0.0001, 0.0, 1.0)
max_distance.add("max_distance_sensor_min_distance", double_t, 0,
                 "Minimal sensor distance.", 0.02, 0.0, 1.0)
max_distance.add("max_distance_display", bool_t, 0,
                 "Display the max distance map.", False)

# Min convexity map parameters.
min_convexity = gen.add_group("min_convexity")
min_convexity.add("min_convexity_use_min_convexity", bool_t, 0,
                  "Use min convexity map.", True)
min_convexity.add("min_convexity_window_size", int_t, 0,
                  "The window size for the neighborhood.", 5, 1, 9)
min_convexity.add("min_convexity_use_morphological_opening", bool_t, 0,
                  "Enable the morphological opening filter.", True)
min_convexity.add("min_convexity_morphological_opening_size", int_t, 0,
                  "Pixel width of the morphological opening filter.", 1, 1, 9)
min_convexity.add(
    "min_convexity_use_threshold", bool_t, 0,
    "Enable a threshold value for the min convexity calculation.", True)
min_convexity.add("min_convexity_step_size", int_t, 0,
                  "The pixel step size of the min convexity filter.", 1, 1, 9)
min_convexity.add("min_convexity_threshold", double_t, 0,
                  "The threshold of what is still convex.", 0.97, 0.0, 1.0)
min_convexity.add("min_convexity_mask_threshold", double_t, 0,
                  "The mask threshold for convexity.", -0.0005, -0.1, 0.1)
min_convexity.add("min_convexity_display", bool_t, 0,
                  "Display the min convexity map.", False)

# Final edge map parameters.
final_edge = gen.add_group("final_edge")
final_edge.add("final_edge_use_morphological_opening", bool_t, 0,
               "Enable the morphological opening filter.", True)
final_edge.add("final_edge_morphological_opening_size", int_t, 0,
               "Pixel width of the morphological opening filter.", 1, 1, 9)
final_edge.add("final_edge_use_morphological_closing", bool_t, 0,
               "Enable the morphological closing filter.", True)
final_edge.add("final_edge_morphological_closing_size", int_t, 0,
               "Pixel width of the morphological closing filter.", 1, 1, 9)
final_edge.add("final_edge_display", bool_t, 0, "Display the final edge map.",
               False)

# Label map parameters.
label = gen.add_group("label")
label.add("label_method", int_t, 0, "The method used to assign the labels.", 1,
          0, 1)
label.add("label_min_size", int_t, 0, "The minimal size of a labeled region.",
          500, 1, 3000)
label.add("label_use_inpaint", bool_t, 0, "Inpaint the label map.", False)
label.add("label_inpaint_method", int_t, 0,
          "Inpaint Method (0: Navier Stokes, 1: Telea).", 0, 0, 1)
label.add("label_display", bool_t, 0, "Display the label map.", True)

exit(gen.generate(PACKAGE, "depth_segmentation", "DepthSegmenter"))
